package com.cmcc.pcap.packet.tcp.tcp;

import java.util.Date;
import java.util.List;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

import com.cmcc.packet.entity.TcpEntity;
import com.cmcc.pcap.packet.tcp.tcp.xdr.TcpXdrGenerate;
import com.cmcc.pcap.jpcap.tcp.TcpPacketDecorator;
import com.cmcc.pcap.packet.tcp.TcpConnection;
import com.cmcc.pcap.packet.tcp.TcpProtocolHandler;


/**
 * @author Amish
 * @Date 2018年3月21日 上午10:06:33
 */
public class TcpHandler extends TcpProtocolHandler<TcpEntity> {

    private static Logger logger = LogManager.getLogger(TcpHandler.class);
    private TcpXdrGenerate txg;

    public TcpHandler() {
    	txg =  new TcpXdrGenerate();
    }

    @Override
    public List<TcpEntity> handle(TcpConnection tcpConnection,String taskId) {
		
    	logger.debug("start execute tcp packet handler");
		logger.debug(new Date(tcpConnection.lastPacketTime));
		long pcapTimestamp = (tcpConnection.al.get(tcpConnection.al.size() - 1)).timestamp.getTime()*1000L;
		logger.debug(new Date(pcapTimestamp));
		List<TcpEntity> xdrTcpEntityList = this.txg.generate(tcpConnection,taskId);
		logger.debug("this connection <" + tcpConnection.connectionKey + "> saved into database !");
		return xdrTcpEntityList;
		
	}
    	

}
